package com.neiquan.backstage.resourec_manage.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neiquan.backstage.common.util.ExtraSpringHibernateTemplate;
import com.neiquan.backstage.pub.bsc.dao.po.Station;
import com.neiquan.backstage.resourec_manage.ResourecStationService;

@Service
public class ResourecStationServiceImp implements ResourecStationService{
	private static Class<?> poc = Station.class;
	@Autowired
	private ExtraSpringHibernateTemplate extraSpringHibernateTemplate;
	
	@Override
	public List<Station> queryByEntrepreneurId(int entrepreneurId,int state,int newlyStuats) {
		// TODO Auto-generated method stub											
		List<Station> listS = (List<Station>) extraSpringHibernateTemplate
				.getHibernateTemplate().find("From Station s where s.leaseId in (select l.leaseId From Lease l where entrepreneurId=? and status=? and newlyStuats=? )", entrepreneurId,state,newlyStuats);
		return listS;
	}
	@Override
	public Station queryByStationId(int stationId) {
		// TODO Auto-generated method stub
		Station entityS = extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "stationId", stationId);
		return entityS;
	}
	@Override
	public List<Station> queryAllByLeaseId(int leaseId ,int state) {
		// TODO Auto-generated method stub
		List<Station> listS = (List<Station>) extraSpringHibernateTemplate.getHibernateTemplate()
		.find("From Station where leaseId=? and state=?", leaseId,state);
		return listS;
	}
	@Override
	public void add(Station entity) {
		extraSpringHibernateTemplate.getHibernateTemplate().save(entity);
	}
	@Override
	public Station queryById(int id) {
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "stationId", id);
	}
	@Override
	public void updata(Station entity) {
		extraSpringHibernateTemplate.getHibernateTemplate().update(entity);
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Station> queryAll() {
		return (List<Station>) extraSpringHibernateTemplate.findAll(poc);
	}
	@Override
	public Station queryByName(String name, Integer memberId) {
		List<Station> roles=(List<Station>) extraSpringHibernateTemplate.getHibernateTemplate().find("From Station where name=? and memberId=?", name,memberId);
		if(roles.size()>0){
			return  roles.get(0);
		}
		return null;
	}
	@Override
	public Station queryByZone(String zone, Integer memberId) {
		List<Station> roles=(List<Station>) extraSpringHibernateTemplate.getHibernateTemplate().find("From Station where zone=? and memberId=?", zone,memberId);
		if(roles.size()>0){
			return  roles.get(0);
		}
		return null;
	}
	

	 
}
